package com.zhangxi.mapper;

import com.github.pagehelper.Page;
import com.zhangxi.annotation.AutoFill;
import com.zhangxi.dto.DishPageQueryDTO;
import com.zhangxi.entity.Dish;
import com.zhangxi.enumeration.OperationType;
import com.zhangxi.vo.DishVo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;
import java.util.Map;

/**
 * ClassName: DishMapper
 * Package: com.zhangxi.mapper
 */
@Mapper
public interface DishMapper {

    /**
     * 菜品表插入数据
     *
     * @param dish
     */
    @AutoFill(OperationType.INSERT)
    void insert(Dish dish);

    /**
     * 开始分页查询菜品
     *
     * @param dishPageQueryDTO
     * @return
     */
    Page<DishVo> pageQuery(DishPageQueryDTO dishPageQueryDTO);

    /**
     * 根据id查询菜品
     * @param id
     * @return
     */
    @Select("select * from dish where id = #{id}")
    Dish getById(Long id);

    /**
     * 根据id删除菜品
     * @param id
     */
    @Delete("delete from dish where id = #{id}")
    void deleteById(Long id);

    /**
     * 更新修改Dish
     * @param dish
     */
    @AutoFill(OperationType.UPDATE)
    void update(Dish dish);


    /**
     * 根据分类id查询菜品
     * @param categoryId
     * @return
     */
    @Select("select * from dish where category_id = #{categoryId}")
    List<Dish> getByCategoryId(Long categoryId);


    /**
     * 增加分类id查询菜品
     * ---增加改造条件
     * @param dish
     * @return
     */
    List<Dish> list(Dish dish);

    /**
     * 根据套餐id查询菜品的全部信息
     * @param id
     * @return
     */
    @Select("select t1.* from dish t1 left join setmeal_dish t2 on t1.id = t2.dish_id where t2.setmeal_id = #{id}")
    List<Dish> getBySetMealId(Long id);

    /**
     * 根据条件统计菜品数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
